﻿package mortal.game.view.copy.worldBoss.worldBossEnter
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.gengine.resource.*;
    import com.gengine.resource.info.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.events.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.common.global.*;
    import mortal.component.rotate3dModelSprite.*;
    import mortal.component.window.*;
    import mortal.game.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.scene3D.model.data.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.guide.*;
    import mortal.game.view.mail.view.*;
    import mortal.mvc.core.*;

    public class WorldBigBossBPanel extends WorldBossBasePanel
    {
        protected var _tabBarBoss:GTabBar2;
        protected var _currentBossName:GImageBitmap;
        protected var _starPanel:StarPanel;
        protected var _tfDes:GTextFiled;
        protected var _tfFeatures:GTextFiled;
        protected var _aryBaseItem:Vector.<MailAttachItem>;
        protected var _tfTimeMsg:GTextFiled;
        protected var _btnMove:GLoadingButton;
        protected var _btnFly:GLoadingButton;
        protected var _imgBeKilled:GImageBitmap;
        private var _rotate3d:Rotate3dModelSprite;
        protected var _img2d:Img2D;
        protected var _rect3d:Rect3DObject;
        protected var _bodyPlayer:ActionPlayer;

        public function WorldBigBossBPanel(param1:BaseWindow, param2:int)
        {
            this._aryBaseItem = new Vector.<MailAttachItem>;
            super(param1, param2);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._tabBarBoss = UICompomentPool.getUICompoment(GTabBar2);
            this._tabBarBoss.cellRenderer = WorldBossListCellRenderer;
            this._tabBarBoss.gap = 10;
            this._tabBarBoss.cellWidth = 223;
            this._tabBarBoss.cellHeight = 78;
            this._tabBarBoss.direction = GBoxDirection.VERTICAL;
            this._tabBarBoss.x = 17;
            this._tabBarBoss.y = 77;
            this._tabBarBoss.configEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.onSelectChange);
            _window.contentTopOf3DSprite.addChild(this._tabBarBoss);
            this._rotate3d = UIFactory.getUICompoment(Rotate3dModelSprite, 260, 70, _window.contentTopOf3DSprite);
            this._rotate3d.setSize(400, 480);
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.WorldBossGuildTips, 250, 84, _window.contentTopOf3DSprite));
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.SplitLineWorldBoss, 642, 172, _window.contentTopOf3DSprite));
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.SplitLineWorldBoss, 642, 230, _window.contentTopOf3DSprite));
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.SplitLineWorldBoss, 642, 360, _window.contentTopOf3DSprite));
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.SplitLineWorldBoss, 642, 446, _window.contentTopOf3DSprite));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.WorldBossMsg, 727, 84, _window.contentTopOf3DSprite));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.WorldBossLevel, 789, 149, _window.contentTopOf3DSprite));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.WorldBossDes, 789, 208, _window.contentTopOf3DSprite));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.WorldBossFeatures, 789, 338, _window.contentTopOf3DSprite));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.WorldBossDrop, 789, 421, _window.contentTopOf3DSprite));
            this._currentBossName = UIFactory.gImageBitmap("", 707, 104, _window.contentTopOf3DSprite);
            this._starPanel = UIFactory.getUICompoment(StarPanel, 0, 0, _window.contentTopOf3DSprite);
            this._starPanel.setStarStyle(ImagesConst.GuildWarStarM, ImagesConst.GuildWarStarMGray, 25);
            this._tfDes = UIFactory.gTextField("", 664, 237, 220, 95, _window.contentTopOf3DSprite, GlobalStyle.textFormatHuang.setIndent(24).setLeading(7));
            this._tfDes.multiline = true;
            this._tfDes.wordWrap = true;
            this._tfFeatures = UIFactory.gTextField("", 664, 365, 220, 45, _window.contentTopOf3DSprite, GlobalStyle.textFormatHuang.setIndent(24).setLeading(7));
            this._tfFeatures.multiline = true;
            this._tfFeatures.wordWrap = true;
            this._tfTimeMsg = UIFactory.gTextField("", 278, 530, 380, 22, _window.contentTopOf3DSprite, GlobalStyle.textFormatBai.center());
            this._btnMove = UIFactory.gLoadingButton(ImagesConst.WorldBossMoveEnter_upSkin, 357, 562, 93, 30, _window.contentTopOf3DSprite);
            this._btnFly = UIFactory.gLoadingButton(ImagesConst.WorldBossFlyEnter_upSkin, 478, 562, 93, 30, _window.contentTopOf3DSprite);
            this._imgBeKilled = UIFactory.gImageBitmap(ImagesConst.WorldBossBeKilled, 390, 300, _window.contentTopOf3DSprite);
            this._imgBeKilled.visible = false;
            this._btnMove.configEventListener(MouseEvent.CLICK, this.onClickBtnMove);
            this._btnFly.configEventListener(MouseEvent.CLICK, this.onClickBtnFly);
            LoaderManager.instance.load(ImagesConst.WorldBossEnterBg + ".swf", this.onResCompl);
            GameProxy.player.getHoleBossStat();
            NetDispatcher.addCmdListener(ServerCommand.WorldBossStatChange, this.updateBossList);
            return;
        }// end function

        private function onResCompl(param1:SWFInfo) : void
        {
            if (!this._rect3d)
            {
                this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(12, 64, 886, 540), _window);
                Rect3DManager.instance.windowShowHander(null, _window);
            }
            this._rect3d.removeImg(this._img2d);
            this._img2d = new Img2D(null, param1.bitmapData, new Rectangle(0, 0, 886, 540), false);
            this._rect3d.addImg(this._img2d);
            this.updateBoss();
            return;
        }// end function

        private function updateBoss() : void
        {
            var _loc_3:String = null;
            var _loc_4:String = null;
            if (!this._rect3d || !this._tabBarBoss || !this._tabBarBoss.dataProvider || this._tabBarBoss.dataProvider.length == 0)
            {
                return;
            }
            var _loc_1:* = this._tabBarBoss.dataProvider[this._tabBarBoss.selectIndex];
            var _loc_2:* = BossConfig.instance.getInfoByCode(_loc_1.bossCode);
            if (!_loc_2)
            {
                MsgManager.showRollTipsMsg("找不到配置的BOSS");
                return;
            }
            _loc_3 = _loc_2.mesh + ".md5mesh";
            _loc_4 = _loc_2.texture;
            var _loc_5:* = _loc_2.bone + ".skeleton";
            if (this._bodyPlayer)
            {
                this._rect3d.disposeObj3d(this._bodyPlayer);
            }
            this._bodyPlayer = FrObjectPool.getObject(ActionPlayer, this);
            this._bodyPlayer.changeAction(ActionName.Stand);
            this._bodyPlayer.selectEnabled = false;
            this._bodyPlayer.play();
            this._bodyPlayer.scaleValue = _loc_1.bossScale * 1 / 100;
            this._bodyPlayer.setRotation(0, 0, 0);
            this._bodyPlayer.load(_loc_3, _loc_5, _loc_4, this._rect3d.renderList);
            this._rect3d.addObject3d(this._bodyPlayer, 450, 450);
            this._bodyPlayer.rotationY = _loc_1.defaultRotate;
            this._rotate3d.model = this._bodyPlayer;
            return;
        }// end function

        private function updateBossStat(param1:Object = null) : void
        {
            var _loc_2:* = this._tabBarBoss.dataProvider[this._tabBarBoss.selectIndex];
            var _loc_3:* = Cache.instance.copy.worldBoss.getBossIsDeath(_loc_2.bossCode);
            this._imgBeKilled.visible = _loc_3;
            this._btnMove.visible = !_loc_3;
            this._btnFly.visible = !_loc_3;
            return;
        }// end function

        protected function updateBossList(param1 = null) : void
        {
            var _loc_2:* = WorldBossConfig.instance.getWorldBossShow(Cache.instance.copy.worldBoss.maxLevel, typeId);
            this._tabBarBoss.dataProvider = _loc_2;
            if (_loc_2.length > 0)
            {
                this.onSelectChange();
            }
            return;
        }// end function

        protected function onSelectChange(event:MuiEvent = null) : void
        {
            var _loc_5:MailAttachItem = null;
            this.updateBoss();
            this.updateBossStat();
            var _loc_2:* = this._tabBarBoss.dataProvider[this._tabBarBoss.selectIndex];
            this._currentBossName.imgUrl = _loc_2.bossNameImage;
            this._starPanel.setStarNum(_loc_2.bossTerroristLevel, _loc_2.bossTerroristLevel);
            this._starPanel.y = 173;
            this._starPanel.x = 885 - _loc_2.bossTerroristLevel * this._starPanel.gat;
            this._tfDes.htmlText = _loc_2.bossDes;
            this._tfFeatures.htmlText = _loc_2.bossFeatures;
            var _loc_3:* = _loc_2.bossDrop.split("#");
            var _loc_4:* = Math.min(this._aryBaseItem.length, _loc_3.length);
            var _loc_6:int = 0;
            _loc_6 = 0;
            while (_loc_6 < _loc_4)
            {
                
                _loc_5 = this._aryBaseItem[_loc_6];
                _loc_5.itemCode = int(_loc_3[_loc_6]);
                _loc_6++;
            }
            _loc_6 = this._aryBaseItem.length - 1;
            while (_loc_6 >= _loc_4)
            {
                
                _loc_5 = this._aryBaseItem[_loc_6];
                _loc_5.dispose();
                this._aryBaseItem.pop();
                _loc_6 = _loc_6 - 1;
            }
            _loc_6 = _loc_4;
            while (_loc_6 < _loc_3.length)
            {
                
                _loc_5 = UIFactory.getUICompoment(MailAttachItem, 678 + 47 * (_loc_6 % 4), 461 + int(_loc_6 / 4) * 45, _window.contentTopOf3DSprite);
                _loc_5.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
                _loc_5.itemCode = int(_loc_3[_loc_6]);
                this._aryBaseItem.push(_loc_5);
                _loc_6++;
            }
            var _loc_7:* = _loc_2.movePoint.split("#");
            var _loc_8:* = _loc_7[0];
            var _loc_9:* = _loc_7[1];
            var _loc_10:* = _loc_7[2];
            var _loc_11:* = GameMapConfig.instance.getMapInfo(_loc_8).name;
            this._tfTimeMsg.htmlText = Language.getStringByParam(21461, _loc_11, _loc_9, _loc_10);
            return;
        }// end function

        protected function onClickBtnMove(event:Event) : void
        {
            var _loc_2:* = this._tabBarBoss.dataProvider[this._tabBarBoss.selectIndex];
            var _loc_3:* = _loc_2.movePoint.split("#");
            var _loc_4:* = _loc_3[0];
            var _loc_5:* = _loc_3[1];
            var _loc_6:* = _loc_3[2];
            var _loc_7:* = new Point(_loc_5, _loc_6);
            GuideEffect.isShowPath = true;
            AIManager.onAIControl(AIType.GoToOtherMap, Game.mapInfo.mapId, _loc_4, _loc_7);
            return;
        }// end function

        protected function onClickBtnFly(event:Event) : void
        {
            var _loc_2:TWorldBoss = null;
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:SPassTo = null;
            var _loc_8:SPoint = null;
            if (this._tabBarBoss && this._tabBarBoss.dataProvider)
            {
                _loc_2 = this._tabBarBoss.dataProvider[this._tabBarBoss.selectIndex];
                if (_loc_2 && _loc_2.flyPoint)
                {
                    _loc_3 = _loc_2.flyPoint.split("#");
                    _loc_4 = _loc_3[0];
                    _loc_5 = _loc_3[1];
                    _loc_6 = _loc_3[2];
                    _loc_7 = new SPassTo();
                    _loc_7.mapId = _loc_4;
                    _loc_8 = new SPoint();
                    _loc_8.x = _loc_5;
                    _loc_8.y = _loc_6;
                    _loc_7.toPoint = _loc_8;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FlyBoot, _loc_7));
                }
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.WorldBossStatChange, this.updateBossList);
            LoaderManager.instance.removeResourceEvent(ImagesConst.WorldBossEnterBg + ".swf", this.onResCompl);
            this._tabBarBoss.dispose(param1);
            this._tabBarBoss = null;
            this._currentBossName.dispose(param1);
            this._currentBossName = null;
            this._starPanel.dispose(param1);
            this._starPanel = null;
            this._tfDes.dispose(param1);
            this._tfDes = null;
            this._tfFeatures.dispose(param1);
            this._tfFeatures = null;
            var _loc_2:int = 0;
            while (_loc_2 < this._aryBaseItem.length)
            {
                
                this._aryBaseItem[_loc_2].dispose(param1);
                _loc_2++;
            }
            this._aryBaseItem.length = 0;
            this._tfTimeMsg.dispose(param1);
            this._tfTimeMsg = null;
            this._btnMove.dispose(param1);
            this._btnMove = null;
            this._btnFly.dispose(param1);
            this._btnFly = null;
            this._imgBeKilled.dispose(param1);
            this._imgBeKilled = null;
            this._rotate3d.dispose(param1);
            this._rotate3d = null;
            if (this._rect3d)
            {
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
                this._bodyPlayer = null;
                this._img2d = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

    }
}
